package com.cy.cur;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CasDemo_1 {


    static int count = 0;


    public static void add() throws InterruptedException {
        TimeUnit.MILLISECONDS.sleep(5);
        count++;
    }


    public static void main(String[] args) throws InterruptedException {

        long start = System.currentTimeMillis();

        int threadSize = 100;

        CountDownLatch countDownLatch = new CountDownLatch(threadSize);
        for (int i = 0; i < threadSize; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        for (int j = 0; j < 10; j++) {
                            add();
                        }
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } finally {
                        countDownLatch.countDown();
                    }
                }
            }).start();
        }
        countDownLatch.await();
        System.out.println(count);
        System.out.println(System.currentTimeMillis() - start);
    }


}
